﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace PlanningGIS.Win.Controls
{
    /// <summary>
    /// 作用：可以在下拉项目（每个item）上显示ToolTip的ComboBox
    /// 作者：吴志宜
    /// 开发时间：2009-06-20
    /// </summary>
    public class ComboBoxTooltips : DevComponents.DotNetBar.Controls.ComboBoxEx
    {
        /// <summary>
        /// 
        /// </summary>
        private ToolTip toolTip1;
        /// <summary>
        /// 
        /// </summary>
        public ComboBoxTooltips()
        {
            this.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
            this.DrawMode = DrawMode.OwnerDrawFixed;
            toolTip1 = new ToolTip();
            this.DrawItem += new DrawItemEventHandler(this.drawItem);
            this.DropDownClosed += new EventHandler(this.dropDownClosed);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void drawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
        {
            // 绘制背景
            e.DrawBackground();
            //绘制列表项目
            e.Graphics.DrawString(this.Items[e.Index].ToString(), e.Font, System.Drawing.Brushes.Black, e.Bounds);
            //将高亮的列表项目的文字传递到toolTip1
            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                toolTip1.Show(this.Items[e.Index].ToString(), this, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + e.Bounds.Height);
            e.DrawFocusRectangle();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dropDownClosed(object sender, System.EventArgs e)
        { 
            toolTip1.Hide(this); 
        }

    }
}
